package com.example.springboot3demo.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class TestService {

    /***
     * 最大重试3次，当遇到 RuntimeException 时重试
     */
    // https://blog.csdn.net/weixin_44792849/article/details/129164817
    // backoff 重试等待策略
    // maxAttempts 最大重试次数
    @Retryable(maxAttempts = 5, retryFor = RuntimeException.class, backoff = @Backoff(delay = 1000, multiplier = 2))
    public void testRetry() {
        log.info("retry....");
        throw new RuntimeException("testRetry");
    }
}
